#include"comm.hpp"

extern Log log;
int main()
{
    int shmid = GetShareMem();
    // log(Debug,"Creat success...");
    char* shmaddr = (char*)shmat(shmid,nullptr,0);//关联
    // log(Debug,"attach success...,shmaddr:0x%x",shmaddr);


    //同步机制
    int fd = open(FIFO_FILE,O_WRONLY);
    if(fd < 0)
    {
        log(Fatal,"open fail...");
        exit(FIFO_OPEN_ERR);
    }

   
    //ipc code: 通信 - 写入
    while(true)
    {
        char buffer[1024];
        cout<<"Please Enter@ ";
        // fgets(shmaddr,sizeof(shmaddr),stdin);//写到buffer

        write(fd,"c",1);//通知读取

        fgets(buffer,sizeof(buffer),stdin);//写到buffer

        memcpy(shmaddr,buffer,strlen(buffer)+1);//把buffer的内容拷贝到shmaddr 当成字符串使用
    }


    shmdt(shmaddr);//去关联
    // log(Debug,"detach success...,shmaddr:0x%x",shmaddr);


    return 0;
}